* Simulation

********generate dataset:
clear all
set seed 25897131
set obs 200
gen time=_n

********generate random disturbances
g disturbance_common = rnormal()/50
gen disturbance_L=rnormal()/50 
gen disturbance_M=rnormal()/50
gen disturbance_H=rnormal()/50 

******** create sine function with amplitude .1 and period 40 ******
* counter-cyclical trend
generate var5 = 0 in 1
replace var5 = 1 in 10
replace var5 = 0 in 20
replace var5 = -1 in 30
replace var5 = 0 in 40
replace var5 = 1 in 50
replace var5 = 0 in 60
replace var5 = -1 in 70
replace var5 = 0 in 80
replace var5 = 1 in 90
replace var5 = 0 in 100
replace var5 = -1 in 110
replace var5 = 0 in 120
replace var5 = 1 in 130
replace var5 = 0 in 140
replace var5 = -1 in 150
replace var5 = 0 in 160
replace var5 = 1 in 170
replace var5 = 0 in 180
replace var5 = -1 in 190
replace var5 = 0 in 200
gen period=3.14*time/20
nl (var5 = {b1}*sin( period ))
predict sin

* pro-cyclical trend
generate var5a = 0 in 1
replace var5a = -1 in 10
replace var5a = 0 in 20
replace var5a = 1 in 30
replace var5a = 0 in 40
replace var5a = -1 in 50
replace var5a = 0 in 60
replace var5a = 1 in 70
replace var5a = 0 in 80
replace var5a = -1 in 90
replace var5a = 0 in 100
replace var5a = 1 in 110
replace var5a = 0 in 120
replace var5a = -1 in 130
replace var5a = 0 in 140
replace var5a = 1 in 150
replace var5a = 0 in 160
replace var5a = -1 in 170
replace var5a = 0 in 180
replace var5a = 1 in 190
replace var5a = 0 in 200
gen perioda=3.14*time/20
nl (var5a = {b1}*sin( perioda ))
predict sina

******** define policy and prefrences:
gen L=.5
gen M=.3
gen H=.1
gen policy=M+sin/20


g L_pref = L+.75*(sin/20)+.25*(sina/20)+.5*disturbance_common+.5*disturbance_L
g M_pref = M+.85*(sin/20)+.15*(sina/20)+.5*disturbance_common+.5*disturbance_M
g H_pref = H+sin/20+.5*disturbance_common+.5*disturbance_H


* Figure 1
twoway /// 
 (line H time, lcolor(gs4)) (line H_pref time, lcolor(gs4)) ///
 (line M_pref time, lcolor(gs8)) (line M time, lcolor(gs8) lwidth(medium)) ///
 (line L_pref time, lcolor(gs12)) (line L time, lcolor(gs12)) /// 
 (area policy time if time<=20 | (time>=40 & time<=60) | (time>=80 & time<=100) | (time>=120 & time<=140) | (time>=160 & time<=180)  , fcolor(gs0%25) lcolor(gs0%0) base(.3)) ///
 (area policy time if (time>=20 & time<=40) | (time>=60 & time<=80)  | (time>=100 & time<=120)  | (time>=140 & time<=160)  | (time>=180) , fcolor(gs12%25) lcolor(gs12%0) base(.3)) ///
 (line policy time, lcolor(gs0)), ytitle(Spending) ymtick(0(.1).6) ylabel(0(.2).6, angle(horizontal)) xtitle(Time) xmtick(0(20)200) xlab(0(40)204) legend(off) ///
text(.5 202 "L", place(e)) text(.3 202 "M", place(e)) text(.1 202 "H", place(e)) text(.36 10 "Deficit", place(n) size(small)) text(.24 30 "Surplus", place(s) size(small))


tsset time
* Table 1
reg d1.policy d1.L_pref d1.M_pref d1.H_pref
prais policy L_pref M_pref H_pref
reg policy L1.policy L_pref M_pref H_pref

